package com.akka;

import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;

public class HelloWorld extends UntypedActor {

	@Override
	public void preStart() throws Exception {
		System.out.println("HelloWrold.preStart() enter...");
	    // create the greeter actor
		System.out.println("HelloWrold.preStart() create the greeter actor.");
	    final ActorRef greeter = getContext().actorOf(Props.create(Greeter.class), "greeter");
	    // tell it to perform the greeting
	    System.out.println("HelloWrold.preStart() tell greet message to Greeter.");
	    greeter.tell(Greeter.Msg.GREET, getSelf());
	    
	    System.out.println("HelloWrold.preStart() exit.");
	}
	
	public void onReceive(Object msg) throws Exception {
		System.out.println("HelloWrold.onReceive() enter...");
		if (msg == Greeter.Msg.DONE){
			System.out.println("HelloWrold.onReceive() receive DONE message to stop self.");
			getContext().stop(getSelf());
		} else {
			System.out.println("HelloWrold.onReceive() unhandled message.");
			unhandled(msg);
		}
		
		System.out.println("HelloWrold.onReceive() exit.");
	};
}
